package com.elock.controller;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.elock.base.core.Page;
import com.elock.base.core.Pageable;
import com.elock.base.core.controller.BaseController;
import com.elock.base.core.controller.ResultMsg;
import com.elock.base.core.util.JsonUtils;
import com.elock.service.MemberService;
import com.elock.service.TerminalNotifyMessageService;

/**
 * Controller - 任务信息
 * @author 仁德
 */
@Controller("terminalNotifyMessageController")
@RequestMapping("/terminal_notify_message")
public class TerminalNotifyMessageController extends BaseController {

	@Resource(name = "terminalNotifyMessageServiceImpl")
	private TerminalNotifyMessageService terminalNotifyMessageService;
	@Resource(name = "memberServiceImpl")
	private MemberService memberService;

	@RequestMapping(value = "/list_tb", method = RequestMethod.GET)
	public String list_tb(ModelMap model) {

		return "/terminal_notify_message/list_tb";
	}

	/**
	 * 列表
	 */
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String list(Pageable pageable, ModelMap model) {

		return "/terminal_notify_message/list";
	}

	/**
	 * 列表数据
	 */
	@RequestMapping(value = "/list_data", method = RequestMethod.POST)
	public @ResponseBody ResultMsg list_data(String terminalNum, String elockNum,
			Integer type, Integer isProcess, String taskSn, String carNumber,
			Pageable pageable, ModelMap model) {

		Object[] args = { terminalNum, elockNum, type, isProcess, taskSn, carNumber };
		Page<Map<String, Object>> page = terminalNotifyMessageService.findPage(pageable,
				args);
		String jsonPage = JsonUtils.toJson(page);

		return success(jsonPage);
	}

	/**
	 * 列表
	 */
	@RequestMapping(value = "/select_list", method = RequestMethod.GET)
	public String select_list(Pageable pageable, ModelMap model) {

		return "/terminal_notify_message/select_list";
	}

	/**
	 * 列表数据
	 */
	@RequestMapping(value = "/select_list_data", method = RequestMethod.POST)
	public @ResponseBody ResultMsg select_list_data(String terminalNum, String elockNum,
			Integer type, String taskSn, String carNumber, Pageable pageable,
			ModelMap model) {

		Object[] args = { terminalNum, elockNum, type, 0, taskSn, carNumber };
		Page<Map<String, Object>> page = terminalNotifyMessageService.findPage(pageable,
				args);
		String jsonPage = JsonUtils.toJson(page);

		return success(jsonPage);
	}

	/**
	 * 获取未处理消息通知数
	 */
	@RequestMapping(value = "/getNoProcess", method = RequestMethod.POST)
	public @ResponseBody ResultMsg getNoProcess() {

		int count = terminalNotifyMessageService.getNoProcess();

		return success().addObjX(count);
	}

	/**
	 * 更新消息通知处理结果
	 */
	@RequestMapping(value = "/updateProcessResult", method = RequestMethod.POST)
	public @ResponseBody ResultMsg updateProcessResult(Long[] ids, String processResult) {

		terminalNotifyMessageService.updateProcessResult(ids,
				processResult,
				memberService.getCurrent().getUsername(),
				null);

		return success();
	}
}
